package com.gable.report.controller;

import com.gable.report.common.util.ReturnResultUtil;
import com.gable.report.model.ChartsHospitalQuery;
import com.gable.report.model.User;
import com.gable.report.service.ChartsForHospitalMaintenanceService;
import com.gable.report.util.ChartsUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 医院报表
 * Created by mj on 2017/7/26.
 */
@Controller
@RequestMapping(value = "charts/hospital")
public class ChartsForHospitalMaintenanceController {
    private final Log logger = LogFactory.getLog(this.getClass());

    @Resource
    HttpServletRequest request;

    @Autowired
    ChartsForHospitalMaintenanceService chartsForHospitalMaintenanceService;

    //医院维护报表跳转页面
    @RequestMapping("/hospital-maintenance/page")
    public String hospitalPage(ChartsHospitalQuery chartsHospitalQuery){
        User user = (User)request.getSession().getAttribute("loginUser");
        return ChartsUtil.checkAuthority(user,chartsHospitalQuery) ? "charts/hospital/department-maintenance" : "charts-authority";
    }

    //医院维护报表
    @RequestMapping(value ="/maintenance/department" ,method= RequestMethod.POST,produces="application/json;charset=utf-8")
    @ResponseBody
    public ReturnResultUtil queryDepartmentAssetsForMaintenance(ChartsHospitalQuery chartsHospitalQuery, HttpServletRequest request) {
        User user = (User) request.getSession().getAttribute("loginUser");
        Long hospitalId = ChartsUtil.getHospitalId(user,chartsHospitalQuery);
        return chartsForHospitalMaintenanceService.queryDepartmentAssetsForMaintenance(hospitalId, chartsHospitalQuery);
    }

    //产品类型维护报表跳转页面
    @RequestMapping("/type-maintenance/page")
    public String deviceTypeSubPage(ChartsHospitalQuery chartsHospitalQuery){
        User user = (User)request.getSession().getAttribute("loginUser");
        return ChartsUtil.checkAuthority(user,chartsHospitalQuery) ? "charts/hospital/type-maintenance" : "charts-authority";
    }

    //产品类型维护报表
    @RequestMapping(value ="/maintenance/type" ,method= RequestMethod.POST,produces="application/json;charset=utf-8")
    @ResponseBody
    public ReturnResultUtil queryDeviceTypeSubAssetsForMaintenance(ChartsHospitalQuery chartsHospitalQuery, HttpServletRequest request) {
        User user = (User) request.getSession().getAttribute("loginUser");
        Long hospitalId = ChartsUtil.getHospitalId(user,chartsHospitalQuery);
        return chartsForHospitalMaintenanceService.queryDeviceTypeSubAssetsForMaintenance(hospitalId, chartsHospitalQuery);
    }

    //厂家维护报表
    @RequestMapping(value ="/maintenance/manufacture" ,method= RequestMethod.POST,produces="application/json;charset=utf-8")
    @ResponseBody
    public ReturnResultUtil queryManufactureAssetsForMaintenance(ChartsHospitalQuery chartsHospitalQuery, HttpServletRequest request) {
        User user = (User) request.getSession().getAttribute("loginUser");
        Long hospitalId = ChartsUtil.getHospitalId(user,chartsHospitalQuery);
        return chartsForHospitalMaintenanceService.queryManufactureAssetsForMaintenance(hospitalId, chartsHospitalQuery);
    }

    //设备型号报表跳转页面
    @RequestMapping("/model-maintenance/page")
    public String modelPage(ChartsHospitalQuery chartsHospitalQuery){
        User user = (User)request.getSession().getAttribute("loginUser");
        return ChartsUtil.checkAuthority(user,chartsHospitalQuery) ? "charts/hospital/model-maintenance" : "charts-authority";
    }

    //设备型号维护报表
    @RequestMapping(value ="/maintenance/model" ,method= RequestMethod.POST,produces="application/json;charset=utf-8")
    @ResponseBody
    public ReturnResultUtil queryModelAssetsForMaintenance(ChartsHospitalQuery chartsHospitalQuery, HttpServletRequest request){
        User user = (User) request.getSession().getAttribute("loginUser");
        Long hospitalId = ChartsUtil.getHospitalId(user,chartsHospitalQuery);
        return chartsForHospitalMaintenanceService.queryModelAssetsForMaintenance(hospitalId, chartsHospitalQuery);
    }

    /**
     * @Description:  设备维护
     * @return
     */
    @RequestMapping(value="/maintenance/assets",method= RequestMethod.POST,produces="application/json;charset=utf-8")
    @ResponseBody
    public ReturnResultUtil queryAssets(ChartsHospitalQuery chartsHospitalQuery, HttpServletRequest request){
        User user = (User) request.getSession().getAttribute("loginUser");
        Long hospitalId = ChartsUtil.getHospitalId(user,chartsHospitalQuery);
        return chartsForHospitalMaintenanceService.queryAssets(hospitalId, chartsHospitalQuery);
    }

    /**
     * @Description:  "➕"号查询设备维护
     * @return
     */
    @RequestMapping(value="/maintenance/device",method= RequestMethod.POST,produces="application/json;charset=utf-8")
    @ResponseBody
    public ReturnResultUtil queryDeviceInfo(ChartsHospitalQuery chartsHospitalQuery, HttpServletRequest request){
        User user = (User) request.getSession().getAttribute("loginUser");
        Long hospitalId = ChartsUtil.getHospitalId(user,chartsHospitalQuery);
        return chartsForHospitalMaintenanceService.queryAssets(hospitalId, chartsHospitalQuery);
    }

    /**
     * @Description:  维护概况
     * @return
     */
    @RequestMapping(value="/maintenance/overview",method= RequestMethod.POST,produces="application/json;charset=utf-8")
    @ResponseBody
    public ReturnResultUtil queryOverview(ChartsHospitalQuery chartsHospitalQuery, HttpServletRequest request){
        User user = (User) request.getSession().getAttribute("loginUser");
        Long hospitalId = ChartsUtil.getHospitalId(user,chartsHospitalQuery);
        return chartsForHospitalMaintenanceService.queryOverview(hospitalId, chartsHospitalQuery);
    }

    /**
     * @Description:  月份维护报表
     * @return
     */
    @RequestMapping(value="/maintenance/month-trend",method= RequestMethod.POST,produces="application/json;charset=utf-8")
    @ResponseBody
    public ReturnResultUtil queryForMonth(ChartsHospitalQuery chartsHospitalQuery, HttpServletRequest request){
        User user = (User) request.getSession().getAttribute("loginUser");
        Long hospitalId = ChartsUtil.getHospitalId(user,chartsHospitalQuery);
        return chartsForHospitalMaintenanceService.queryForMonth(hospitalId, chartsHospitalQuery);
    }

    /**
     * @Description:  巡检数据
     * @param chartsHospitalQuery
     * @return
     */
    @RequestMapping(value="/maintenance/queryInspectionData",method= RequestMethod.POST,produces="application/json;charset=utf-8")
    @ResponseBody
    public ReturnResultUtil queryInspectionData(ChartsHospitalQuery chartsHospitalQuery, HttpServletRequest request){
        User user = (User) request.getSession().getAttribute("loginUser");
        Long hospitalId = ChartsUtil.getHospitalId(user,chartsHospitalQuery);
        return chartsForHospitalMaintenanceService.queryInspectionData(hospitalId, chartsHospitalQuery);
    }

    /**
     * @Description:  强检数据
     * @param chartsHospitalQuery
     * @return
     */
    @RequestMapping(value="/maintenance/queryCompulsoryData",method= RequestMethod.POST,produces="application/json;charset=utf-8")
    @ResponseBody
    public ReturnResultUtil queryCompulsoryData(ChartsHospitalQuery chartsHospitalQuery, HttpServletRequest request){
        User user = (User) request.getSession().getAttribute("loginUser");
        Long hospitalId = ChartsUtil.getHospitalId(user,chartsHospitalQuery);
        return chartsForHospitalMaintenanceService.queryCompulsoryData(hospitalId, chartsHospitalQuery);
    }

    /**
     * @Description:  保养数据
     * @param chartsHospitalQuery
     * @return
     */
    @RequestMapping(value="/maintenance/queryUpkeepData",method= RequestMethod.POST,produces="application/json;charset=utf-8")
    @ResponseBody
    public ReturnResultUtil queryUpkeepData(ChartsHospitalQuery chartsHospitalQuery, HttpServletRequest request){
        User user = (User) request.getSession().getAttribute("loginUser");
        Long hospitalId = ChartsUtil.getHospitalId(user,chartsHospitalQuery);
        return chartsForHospitalMaintenanceService.queryUpkeepData(hospitalId, chartsHospitalQuery);
    }


    /**
     * @Author: 杨青桦
     * @Description: 查询计划设备信息
     * @Date: 2017/12/22 11:22
     * @param chartsHospitalQuery
     * @param request
     * @return
     */
    @RequestMapping(value="/maintenance/plan/device",method= RequestMethod.POST,produces="application/json;charset=utf-8")
    @ResponseBody
    public ReturnResultUtil queryPlanAssets(ChartsHospitalQuery chartsHospitalQuery, HttpServletRequest request){
        User user = (User) request.getSession().getAttribute("loginUser");
        Long hospitalId = ChartsUtil.getHospitalId(user,chartsHospitalQuery);
        return chartsForHospitalMaintenanceService.queryPlanAssets(hospitalId, chartsHospitalQuery);
    }

    /**
     * @Author: 杨青桦
     * @Description:  查询计划记录信息
     * @Date: 2017/12/22 14:34
     * @param chartsHospitalQuery
     * @param request
     * @return
     */
    @RequestMapping(value="/maintenance/plan/record",method= RequestMethod.POST,produces="application/json;charset=utf-8")
    @ResponseBody
    public ReturnResultUtil queryPlanRecords(ChartsHospitalQuery chartsHospitalQuery, HttpServletRequest request){
        User user = (User) request.getSession().getAttribute("loginUser");
        Long hospitalId = ChartsUtil.getHospitalId(user,chartsHospitalQuery);
        return chartsForHospitalMaintenanceService.queryPlanRecords(hospitalId, chartsHospitalQuery);
    }

    /**
     * @Author: 杨青桦
     * @Description:  查询实际维护设备信息
     * @Date: 2017/12/22 14:34
     * @param chartsHospitalQuery
     * @param request
     * @return
     */
    @RequestMapping(value="/maintenance/actual/device",method= RequestMethod.POST,produces="application/json;charset=utf-8")
    @ResponseBody
    public ReturnResultUtil queryActualAssets(ChartsHospitalQuery chartsHospitalQuery, HttpServletRequest request){
        User user = (User) request.getSession().getAttribute("loginUser");
        Long hospitalId = ChartsUtil.getHospitalId(user,chartsHospitalQuery);
        return chartsForHospitalMaintenanceService.queryActualAssets(hospitalId, chartsHospitalQuery);
    }
}
